package com.scy.service.impl;

import com.scy.anno.Autowired;
import com.scy.anno.Service;
import com.scy.anno.Transactional;
import com.scy.dao.AccountDao;
import com.scy.pojo.Account;
import com.scy.service.TransferService;
@Service(value = "transferService")
@Transactional()
public class TransferServiceImpl implements TransferService {

    @Autowired
    private AccountDao accountDao;


    @Override
    public void transfer(String fromCardNo, String toCardNo, int money) throws Exception {
            Account from = accountDao.queryAccountByCardNo(fromCardNo);
            Account to = accountDao.queryAccountByCardNo(toCardNo);
            from.setMoney(from.getMoney()-money);
            to.setMoney(to.getMoney()+money);
            accountDao.updateAccountByCardNo(from);
            //int i = 1/0;
            accountDao.updateAccountByCardNo(to);
    }
}
